using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.dir
{
	public class frmSaveCollection : Form
	{
		private Func objFunc = new Func();
		private DataSet ds = new DataSet();
		private SqlDataAdapter da = new SqlDataAdapter();
		private bool add = false;
		private IContainer components = null;
		private DataGridView dgvRep;
		private DataGridViewTextBoxColumn dg2;
		private DataGridViewTextBoxColumn Column1;
		private Button btnDel;
		private Button tSBClose;
		private Button tSBSave;
		private Button tSBAdd;
		private TextBox txtID;
		private TextBox txtName;
		public frmSaveCollection()
		{
			this.InitializeComponent();
		}
		private void frmSaveCollection_Load(object sender, EventArgs e)
		{
			this.dgvRep.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			sqlConnection.Open();
			SqlCommand selectCommand = new SqlCommand("SELECT * FROM [TabSaveCondition]", sqlConnection);
			this.da.SelectCommand = selectCommand;
			this.da.Fill(this.ds);
			this.dgvRep.DataSource = this.ds.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void dgvRep_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.txtID.Text = this.dgvRep.Rows[e.RowIndex].Cells[0].Value.ToString();
				this.txtName.Text = this.dgvRep.Rows[e.RowIndex].Cells[1].Value.ToString();
				this.txtID.ReadOnly = false;
				this.txtName.ReadOnly = false;
				this.add = false;
			}
			catch
			{
			}
		}
		private void tSBAdd_Click(object sender, EventArgs e)
		{
			this.add = true;
			this.txtID.ReadOnly = false;
			this.txtName.ReadOnly = false;
			this.txtID.Text = "";
			this.txtName.Text = "";
			this.btnDel.Enabled = false;
			this.tSBSave.Enabled = true;
			this.txtID.Focus();
		}
		private void tSBSave_Click(object sender, EventArgs e)
		{
			this.txtID.ReadOnly = true;
			this.txtName.ReadOnly = true;
			this.btnDel.Enabled = true;
			if (this.txtID.Text != "" && this.txtName.Text != "")
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand;
				if (this.add)
				{
					sqlCommand = new SqlCommand(string.Concat(new string[]
					{
						"INSERT INTO [TabSaveCondition] VALUES('",
						this.txtID.Text,
						"',N'",
						this.txtName.Text,
						"')"
					}), sqlConnection);
					sqlCommand.ExecuteNonQuery();
				}
				else
				{
					sqlCommand = new SqlCommand(string.Concat(new string[]
					{
						"UPDATE [TabSaveCondition] SET Name = N'",
						this.txtName.Text,
						"' WHERE [ID] = '",
						this.txtID.Text,
						"'"
					}), sqlConnection);
					sqlCommand.ExecuteNonQuery();
				}
				this.ds.Tables[0].Clear();
				sqlCommand = new SqlCommand("SELECT * FROM [TabSaveCondition]", sqlConnection);
				this.da.SelectCommand = sqlCommand;
				this.da.Fill(this.ds);
				this.dgvRep.AutoGenerateColumns = false;
				this.dgvRep.DataSource = this.ds.Tables[0];
				sqlConnection.Close();
				sqlConnection.Dispose();
				this.txtID.ReadOnly = true;
				this.txtName.ReadOnly = true;
				this.add = false;
			}
			else
			{
				MessageBox.Show("Nhập đầy đủ thông tin trước khi lưu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.txtID.Focus();
			}
		}
		private void tSBClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmSaveCollection_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F4)
			{
				this.tSBAdd.PerformClick();
			}
			else
			{
				if (e.KeyCode == Keys.F6)
				{
					this.tSBSave.PerformClick();
				}
				else
				{
					if (e.KeyCode == Keys.F8)
					{
						this.btnDel.PerformClick();
					}
					else
					{
						if (e.KeyCode == Keys.Escape)
						{
							this.tSBClose.PerformClick();
						}
					}
				}
			}
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			if (this.txtID.Text != "" && this.txtName.Text != "")
			{
				if (MessageBox.Show("Bạn có chắc chắn muốn xoá thông tin này không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
					sqlConnection.Open();
					SqlCommand sqlCommand = new SqlCommand("DELETE FROM [TabSaveCondition] WHERE [ID] = '" + this.txtID.Text + "'", sqlConnection);
					sqlCommand.ExecuteNonQuery();
					this.ds.Tables[0].Clear();
					sqlCommand = new SqlCommand("SELECT * FROM [TabSaveCondition]", sqlConnection);
					this.da.SelectCommand = sqlCommand;
					this.da.Fill(this.ds);
					this.dgvRep.AutoGenerateColumns = false;
					this.dgvRep.DataSource = this.ds.Tables[0];
					sqlConnection.Close();
					sqlConnection.Dispose();
				}
				this.txtID.ReadOnly = true;
				this.txtName.ReadOnly = true;
				this.add = false;
			}
			else
			{
				this.txtID.Focus();
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			this.dgvRep = new DataGridView();
			this.dg2 = new DataGridViewTextBoxColumn();
			this.Column1 = new DataGridViewTextBoxColumn();
			this.btnDel = new Button();
			this.tSBClose = new Button();
			this.tSBSave = new Button();
			this.tSBAdd = new Button();
			this.txtID = new TextBox();
			this.txtName = new TextBox();
			((ISupportInitialize)this.dgvRep).BeginInit();
			base.SuspendLayout();
			this.dgvRep.AllowUserToAddRows = false;
			this.dgvRep.AllowUserToDeleteRows = false;
			this.dgvRep.AllowUserToResizeColumns = false;
			this.dgvRep.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dgvRep.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvRep.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvRep.BackgroundColor = Color.White;
			this.dgvRep.BorderStyle = BorderStyle.Fixed3D;
			dataGridViewCellStyle2.BackColor = SystemColors.Control;
			dataGridViewCellStyle2.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			dataGridViewCellStyle2.ForeColor = SystemColors.WindowText;
			dataGridViewCellStyle2.SelectionBackColor = Color.Aqua;
			dataGridViewCellStyle2.SelectionForeColor = Color.Black;
			this.dgvRep.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvRep.ColumnHeadersHeight = 26;
			this.dgvRep.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvRep.Columns.AddRange(new DataGridViewColumn[]
			{
				this.dg2,
				this.Column1
			});
			this.dgvRep.Cursor = Cursors.Hand;
			this.dgvRep.EnableHeadersVisualStyles = false;
			this.dgvRep.Location = new Point(7, 7);
			this.dgvRep.Name = "dgvRep";
			this.dgvRep.ReadOnly = true;
			this.dgvRep.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
			dataGridViewCellStyle3.BackColor = SystemColors.Control;
			dataGridViewCellStyle3.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			dataGridViewCellStyle3.ForeColor = Color.Black;
			dataGridViewCellStyle3.SelectionBackColor = Color.Aqua;
			dataGridViewCellStyle3.SelectionForeColor = Color.Black;
			this.dgvRep.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
			this.dgvRep.RowHeadersVisible = false;
			this.dgvRep.RowHeadersWidth = 26;
			this.dgvRep.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvRep.RowsDefaultCellStyle = dataGridViewCellStyle4;
			this.dgvRep.RowTemplate.DefaultCellStyle.BackColor = Color.White;
			this.dgvRep.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dgvRep.RowTemplate.DefaultCellStyle.ForeColor = Color.Black;
			this.dgvRep.RowTemplate.DefaultCellStyle.SelectionBackColor = Color.Aqua;
			this.dgvRep.RowTemplate.DefaultCellStyle.SelectionForeColor = Color.Black;
			this.dgvRep.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvRep.Size = new Size(421, 189);
			this.dgvRep.TabIndex = 22;
			this.dgvRep.CellEnter += new DataGridViewCellEventHandler(this.dgvRep_CellEnter);
			this.dg2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.dg2.DataPropertyName = "ID";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle5.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle5.NullValue = null;
			this.dg2.DefaultCellStyle = dataGridViewCellStyle5;
			this.dg2.HeaderText = "Số hiệu";
			this.dg2.MinimumWidth = 120;
			this.dg2.Name = "dg2";
			this.dg2.ReadOnly = true;
			this.Column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column1.DataPropertyName = "Name";
			this.Column1.HeaderText = "Tên gọi";
			this.Column1.MinimumWidth = 120;
			this.Column1.Name = "Column1";
			this.Column1.ReadOnly = true;
			this.btnDel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnDel.BackColor = SystemColors.ControlLight;
			this.btnDel.Cursor = Cursors.Hand;
			this.btnDel.FlatAppearance.BorderColor = Color.Gray;
			this.btnDel.FlatStyle = FlatStyle.System;
			this.btnDel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnDel.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnDel.Location = new Point(213, 230);
			this.btnDel.Name = "btnDel";
			this.btnDel.Size = new Size(100, 30);
			this.btnDel.TabIndex = 25;
			this.btnDel.Text = "Xoá bỏ [ F8 ]";
			this.btnDel.UseVisualStyleBackColor = false;
			this.btnDel.Click += new EventHandler(this.btnDel_Click);
			this.tSBClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.tSBClose.BackColor = SystemColors.ControlLight;
			this.tSBClose.Cursor = Cursors.Hand;
			this.tSBClose.FlatAppearance.BorderColor = Color.Gray;
			this.tSBClose.FlatStyle = FlatStyle.System;
			this.tSBClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tSBClose.ImageAlign = ContentAlignment.MiddleLeft;
//			this.tSBClose.ImeMode = ImeMode.NoControl;
			this.tSBClose.Location = new Point(333, 230);
			this.tSBClose.Name = "tSBClose";
			this.tSBClose.Size = new Size(95, 30);
			this.tSBClose.TabIndex = 26;
			this.tSBClose.Text = "Thoát  [ ESC ]";
			this.tSBClose.UseVisualStyleBackColor = false;
			this.tSBClose.Click += new EventHandler(this.tSBClose_Click);
			this.tSBSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.tSBSave.BackColor = SystemColors.ControlLight;
			this.tSBSave.Cursor = Cursors.Hand;
			this.tSBSave.FlatAppearance.BorderColor = Color.Gray;
			this.tSBSave.FlatStyle = FlatStyle.System;
			this.tSBSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tSBSave.ImageAlign = ContentAlignment.MiddleLeft;
//			this.tSBSave.ImeMode = ImeMode.NoControl;
			this.tSBSave.Location = new Point(110, 230);
			this.tSBSave.Name = "tSBSave";
			this.tSBSave.Size = new Size(100, 30);
			this.tSBSave.TabIndex = 24;
			this.tSBSave.Text = "Ghi nhận [ F6 ]";
			this.tSBSave.UseVisualStyleBackColor = false;
			this.tSBSave.Click += new EventHandler(this.tSBSave_Click);
			this.tSBAdd.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.tSBAdd.BackColor = SystemColors.ControlLight;
			this.tSBAdd.Cursor = Cursors.Hand;
			this.tSBAdd.FlatAppearance.BorderColor = Color.Gray;
			this.tSBAdd.FlatStyle = FlatStyle.System;
			this.tSBAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.tSBAdd.ImageAlign = ContentAlignment.MiddleLeft;
//			//this.tSBAdd.ImeMode = ImeMode.NoControl;
			this.tSBAdd.Location = new Point(7, 230);
			this.tSBAdd.Name = "tSBAdd";
			this.tSBAdd.Size = new Size(100, 30);
			this.tSBAdd.TabIndex = 23;
			this.tSBAdd.Text = "Thêm mới [ F4 ]";
			this.tSBAdd.UseVisualStyleBackColor = false;
			this.tSBAdd.Click += new EventHandler(this.tSBAdd_Click);
			this.txtID.BackColor = Color.White;
			this.txtID.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtID.Location = new Point(7, 202);
			this.txtID.Name = "txtID";
			this.txtID.ReadOnly = true;
			this.txtID.Size = new Size(100, 22);
			this.txtID.TabIndex = 27;
			this.txtName.BackColor = Color.White;
			this.txtName.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtName.Location = new Point(110, 202);
			this.txtName.Name = "txtName";
			this.txtName.ReadOnly = true;
			this.txtName.Size = new Size(318, 22);
			this.txtName.TabIndex = 28;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(434, 266);
			base.Controls.Add(this.txtName);
			base.Controls.Add(this.txtID);
			base.Controls.Add(this.btnDel);
			base.Controls.Add(this.tSBClose);
			base.Controls.Add(this.tSBSave);
			base.Controls.Add(this.tSBAdd);
			base.Controls.Add(this.dgvRep);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(450, 300);
			this.MinimumSize = new Size(450, 300);
			base.Name = "frmSaveCollection";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "..: Điều kiện bảo quản";
			base.Load += new EventHandler(this.frmSaveCollection_Load);
			base.KeyDown += new KeyEventHandler(this.frmSaveCollection_KeyDown);
			((ISupportInitialize)this.dgvRep).EndInit();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
